import axios from "axios";
//import {message} from 'antd'

const http = axios.create({
  baseURL: process.env.REACT_APP_API,
  timeout: 30000,
});

http.interceptors.request.use(
  (config) => {
    // do something before request is sent
    return config;
  },
  (error) => {
    // do something with request error
    console.log("请求时发生错误"); // for debug
    return Promise.reject(error);
  }
);

http.interceptors.response.use(
  (response) => {
    const res = response.data;
    // if (!res.success) {
    // }
    return res;
  },
  (error) => {
    //console.log('err' + error) // for debug
    // const res = error.response.data;
    // if (res.message) {
    // } else {
    //   console.log("请求结束时错误");
    // }
    return Promise.reject(error);
  }
);

export default http;
